﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Avin.Infrastructure
{
    public static class JsonHelper
    {
        public static string ToJson(this object obj)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                DateFormatString = "yyyy-MM-dd HH:mm:ss"
            };
            return JsonConvert.SerializeObject(obj, settings);
        }

        public static T JsonToObject<T>(this string str)
        {
            return JsonConvert.DeserializeObject<T>(str);
        }
    }
}
